import { Body, Controller, DefaultValuePipe, Get, Param, ParseIntPipe, Post, UsePipes } from '@nestjs/common';
import { AppService } from './app.service';
import { PrismaClient } from '@prisma/client';
import { HdPipe } from './hd.pipe';
import CreateArticleDto from './dto/create.article.dto';

@Controller()
export class AppController {
  prisma:PrismaClient
  constructor(private readonly appService: AppService) {
    this.prisma = new PrismaClient();
  }

  @Get(':id')
  getHello(@Param('id', new DefaultValuePipe(1) ,ParseIntPipe) id:number) {
    return this.prisma.article.findUnique({
      where:{
        id,
      }
    }) 
  }

  @Post('store')
  async add(@Body() dto:CreateArticleDto){
    const article = await this.prisma.article.create({
      data:{
        title:dto.title,
        content:dto.content
      }
    })
    console.log(article);
  }
}
